package com.xiaoba.search.controller;


import com.xiaoba.common.core.domain.Result;
import com.xiaoba.search.domain.SearchParam;
import com.xiaoba.search.domain.SearchResult;
import com.xiaoba.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Gd
 * @package: com.xiaoba.search.controller
 * @Project: XiaoBa
 * @Name: SearchController
 * @Date: 2024/5/29 15:23
 */
@RestController
@RequestMapping("/es")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * from表单查询
     */
    @GetMapping("product")
    public Result<SearchResult> seachProduct(SearchParam searchParam){
        try{
            SearchResult result = searchService.seach(searchParam);
            return Result.success(result);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }

    }

    /**
     * 上架同步
     * @param id
     * @return
     */
    @GetMapping("sendputaway/{id}")
    public Result sendputaway(@PathVariable("id")Integer id){
        searchService.delsAll();
        Result sendputaway = searchService.sendputaway(id);
        return sendputaway;
    }

}
